<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


    /**
    * Klasa Object_attributes controller obavlja validaciju podataka i komunicira sa modelom.
    * 
    * Vraca podatke korisnikckoj aplikaciji.
    * @author NU SIT Bar
    * @version 1.0
    * @created 15-Aug-2012 1:41:14 PM
    */
    class Object_attributes extends CI_Controller
    {

        /**
        * Attribute type
        */
        var $type;
        /**
        * post_action, can be NEW || EDIT
        */
        var $action;

        function __construct(){
            parent::__construct();
            $this->load->model('codegen_model');
        }



        /**
        * Return view of all attributes for given type
        * 
        * @param post_type
        */
        function view_all($post_type)
        {
        }

        /**
        * 
        * @param ID
        */
        function view_edit($ID)
        {
        }

        /**
        * 
        * @param post_type
        */
        function view_new($type=NULL)
        {
            $this->data['page'] = 'attributes';
            $this->data['title'] = 'Novi atribut objektu';
            $this->data['attributes'] = $this->codegen_model->get('attributes','*','',999999);
            echo $this->load->view('object_attributes/new_object_attribute',$this->data,TRUE);

        }

        /**
        * 
        * @param post_action
        * @param post_ID
        */
        function submit_post()
        {

            if ($this->form_validation->run('object_attributes') == false)
            {
                echo json_encode(array('action'=>FALSE, 'msg'=>validation_errors()));
            } 
            else
            {                            

                unset($_POST['post_action']);

                if ($this->codegen_model->add('object_attributes',$_POST) == TRUE)
                {
                    echo json_encode(array('action'=>true,'msg'=>'Successful insert operation.'));
                }
                else
                {
                    echo json_encode(array('action'=>FALSE, 'msg'=>'<p>An Error Occured.</p>')); 

                }
            }

        }

        function delete($post_ID){

            /*if($this->owners_model->delete_owner($post_ID)){
            $this->view_all();
            }else{
            echo 'Error ocured';
            $this->view_all();
            }*/

        }

        function dropdown_check($str)
        {
            $CI =& get_instance();

            $CI->form_validation->set_message('dropdown_check', 'Please select %s.');

            return ($str=='0') ? FALSE : TRUE;
        }


}